import Swiper from 'swiper'

let SwiperInfo = null;

const SwiperFn = (delay) => {
    console.log(1)
    let swiperInfo21 = new Swiper('.swiper-container', {
        loop: true,
        slidesPerView: 5,
        spaceBetween: 0,
        slidesPerGroup: 1,
        current: 0,
        loopAdditionalSlides: 1,
        loopFillGroupWithBlank: true,
        slideToClickedSlide: true,
        normalizeSlideIndex: false,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        on: {
            click(e) {
                console.log('1.滑动结束')
            },
            slideChange: () => {
                console.log('2.滑动结束')
            },
        },
    });
    let swiperInfo2 = new Swiper('.swiper-container',{
        slidesPerView: 5,
        spaceBetween: 0,
        slidesPerGroup: 5,
        loop: true,
        autoplay: {
            delay:2000
        },
        loopFillGroupWithBlank: true,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });
    return SwiperInfo = swiperInfo2;
};

export default {
    binding(el, binding, vnode) {
        console.log('binding');
    },

    inserted(el, binding, vnode) {
        let {delay,index,length} = binding.value;
        if (!SwiperInfo) {
            SwiperInfo = SwiperFn(delay || 5000);
        } else {
            SwiperInfo.update();
        }
    },

    updated(el, binding, vnode, oldVnode) {
        let {delay,index,length} = binding.value;
        if (!SwiperInfo) {
            SwiperInfo = SwiperFn(delay || 5000);
        } else {
            SwiperInfo.update();
        }
    },

    componentUpdated(el, binding, vnode, oldVnode) {
        let {delay,index,length} = binding.value;
        if (!SwiperInfo) {
            SwiperInfo = SwiperFn(delay || 5000);
        } else {
            SwiperInfo.update();
        }
    },

    unbind(el, binding, vnode) {
        SwiperInfo = null
    }
}